matlab函数详解

您所在的位置:网站首页 matlab 保存视频 matlab函数详解

matlab函数详解

2024-07-11 19:44| 来源: 网络整理| 查看: 265

最近需要使用matlab读取摄像头,并显示图像在gui上面,好像没有现成可以用的,这里试试。

文章目录 自带例程实现gui界面显示摄像头采集内容下面对preview的注释进行翻译**下面对preview的函数解释进行总结**

自带例程

matlab的preview函数中的例程:调用摄像头,并显示

obj = videoinput('winvideo',1,'MJPG_160x120'); % set(obj,'ReturnedColorSpace','grayscale');%变成灰色的 figure('Name', 'My Custom Preview Window'); uicontrol('String', 'Close', 'Callback', 'close(gcf)'); % Create an image object for previewing. vidRes = get(obj, 'VideoResolution');%视频分辨率 nBands = get(obj, 'NumberOfBands');%谱带数量 hImage = image( zeros(vidRes(2), vidRes(1), nBands) ); preview(obj, hImage);

例程运行的结果如下图,只能改变视频分辨率和谱带数量,我需要把这个图像放入自己的gui里面。 在这里插入图片描述

实现gui界面显示摄像头采集内容

这里参数都根据自己需求改,主要是要把handles.axes1加入hImage中,即可实现。

vid = videoinput('winvideo',1,'YUY2_320x240'); set(vid,'ReturnedColorSpace','grayscale'); vidRes = get(vid, 'VideoResolution');%视频分辨率 nBands = get(vid, 'NumberOfBands');%谱带数量 hImage = image(zeros(vidRes(2),vidRes(1),nBands),'parent',handles.axes1 ); preview(vid, hImage);

在这里插入图片描述

下面对preview的注释进行翻译 function outputhandle = preview(obj, targetImage) %PREVIEW Display preview of live video data. % % PREVIEW(OBJ) creates a Video Preview window that displays live video % data for video input object OBJ. The window also displays the timestamp % and video resolution of each frame, and the current status of OBJ. The % Video Preview window displays the video data at 100% magnification (one % screen pixel represents one image pixel). The size of the preview image % is determined by the value of the video input object ROIPosition % property.

PREVIEW(OBJ)创建显示实时视频的视频预览窗口视频输入对象OBJ的%数据。 该窗口还显示时间戳和每帧的视频分辨率,以及OBJ的当前状态。这视频预览窗 口以100%的放大率显示视频数据(一屏幕像素代表一个图像像素)。预览图像的 大小由视频输入对象ROIPosition属性值决定。

% The Video Preview window remains active until it is either stopped using % STOPPREVIEW or closed using CLOSEPREVIEW. If you delete the object, % DELETE(OBJ), the Video Preview window stops previewing and closes % automatically.

视频预览窗口保持活动状态,直到停止使用 STOPPREVIEW或使用CLOSEPREVIEW关闭。如果删除该对象, 删除(OBJ),视频预览窗口停止预览并自动关闭。

% PREVIEW(OBJ, HIMAGE) displays live video data for video input object % OBJ in the image object specified by the handle HIMAGE. PREVIEW scales % the image data to fill the entire area of the image object but does not % modify the values of any image object properties. Use this syntax to % preview video data in a custom GUI of your own design (see Examples).

PREVIEW(OBJ,HIMAGE)显示由结构HIMAGE指定的图像对象中视频输入对象OBJ的实时视频数据。预览缩放图像数据以填充图像对象的整个区域,但不修改任何图像对象属性的值。使用此语法在您自己设计的自定义图形用户界面中预览视频数据(参见示例)。

% HIMAGE = PREVIEW(...) returns HIMAGE, a handle to the image object % containing the previewed data. To obtain a handle to the figure window % containing the image object, use ANCESTOR. For more information about % using image objects, see IMAGE. See the Custom Update Function section % for more information about the image object returned.

% HIMAGE = PREVIEW(…)返回HIMAGE,图像对象的句柄 %包含预览的数据。获取图形窗口的句柄 %包含图像对象,请使用EXTENSION。有关使用图像对象的更多信息 %,请参见图像。请参见自定义更新功能部分 %获取有关返回的图像对象的更多信息。

% If you specify the image object where you want PREVIEW to display % video data, you can also specify a function that PREVIEW calls for % every update. PREVIEW assigns application-defined data, specified by % the name 'UpdatePreviewWindowFcn', to the image object, HIMAGE. Use % the SETAPPDATA function, to set the value of 'UpdatePreviewWindowFcn' % to a function handle that PREVIEW will invoke for each update. You can % use this function to perform custom processing of the previewed image % data. If 'UpdatePreviewWindowFcn' is configured to [] (the default), % PREVIEW ignores it. If it is configured to any value other than a % function handle or [], PREVIEW errors.

%如果您指定要预览显示视频数据的图像对象,您还可以指定每次更新时预览调用的函数。预览将应用程序定义的数据(由名称“UpdatePreviewWindowFcn”指定)分配给图像对象HIMAGE。使用SETAPPDATA函数,将“更新预览窗口”的值设置为每次更新预览都会调用的函数句柄。 您可以使用此功能对预览的图像数据进行自定义处理。如果“UpdatePreviewWindowFcn”配置为,预览将忽略它。如果它被配置为除函数句柄或[]之外的任何值,则会出现PREVIEW错误。

% The 'UpdatePreviewWindowFcn' will not necessarily be called for every % frame that is acquired. If a new frame is acquired and the % 'UpdatePreviewWindowFcn' for the previous frame has not yet finished % executing, no update will be generated for the new frame. If you need % to execute a function for every acquired frame, use the % FramesAcquiredFcn instead.

%对于获取的每个帧,不一定会调用“更新预览窗口”。如果获取了新帧,并且前一帧的“更新预览窗口”尚未完成执行,则不会为新帧生成更新。如果您需要为每个获取的帧执行一个函数,请改用FramesAcquiredFcn。

下面对preview的函数解释进行总结 preview(OBJ)能够显示摄像头采集的视频,时间戳和每帧的视频分辨率使用stoppreview,closepreview或者delete函数能够实现停止显示的功能。previer(obj,himage),就是使用句柄(属性描述结构)himage设计的自定义图形用户界面中预览视频数据himage=previer(obj),就是获取句柄(属性描述结构),并显示himage可以添加UpdatePreviewWindowFcn一个函数对预览的图像数据进行自定义处理FramesAcquiredFcn实现对每一帧都进行处理,而UpdatePreviewWindowFcn是上一帧没有处理完,那么新采集的帧就不会处理pdatePreviewWindowFcn负责显示图像对象中的视频数据。您的函数可以在显示数据之前、显示数据之后或两者都处理数据。 set(HIMAGE, 'CData', event.Data)


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3